package cn.factorybox.common.utils.resultUtils;

import cn.factorybox.model.entity.DeviceData;
import cn.factorybox.model.entity.JudgeValue;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-03-16 13:45
 */
public class WarningCountUtils {

    public static Map<String,Integer> warningCount(List<DeviceData> list,int type, List<JudgeValue> judges) {
        Map<String,Integer> map = new HashMap<>();
        map.put("allcount",0);
        map.put("tempcount",0);
        map.put("humcount",0);
        map.put("cotwocount",0);
        map.put("tvoccount",0);
        map.put("aircount",0);
        map.put("presscount",0);
        map.put("pm25count",0);

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getResult().equals("不适")) {
                int allcount = map.get("allcount");
                allcount ++;
                map.put("allcount",allcount);
            }
            if (type == 0) {
                indoorWarningCount(list.get(i),map,judges);
            } else if (type == 1) {
                experWarningCount(list.get(i),map,judges);
            } else if (type == 2) {
                outdoorWarningCount(list.get(i),map,judges);
            }
        }
        return map;
    }

    public static void indoorWarningCount(DeviceData deviceData, Map<String,Integer> map, List<JudgeValue> judges) {
        if (deviceData.getfTemperature() < judges.get(0).getWeixianMin() || deviceData.getfTemperature() > judges.get(0).getWeixianMax()) {
            int tempcount = map.get("tempcount");
            tempcount ++;
            map.put("tempcount",tempcount);
        }
        if (deviceData.getfHumidity() < judges.get(1).getWeixianMin() || deviceData.getfHumidity() > judges.get(1).getWeixianMax()) {
            int humcount = map.get("humcount");
            humcount ++;
            map.put("humcount",humcount);
        }
        if ((deviceData.getfPressure()) < judges.get(2).getWeixianMin() || (deviceData.getfPressure()) > judges.get(2).getWeixianMax()) {
            int presscount = map.get("presscount");
            presscount ++;
            map.put("presscount",presscount);
        }
        if (deviceData.getfExhaust() >= judges.get(3).getWeixianMin() && deviceData.getfExhaust() < judges.get(3).getWeixianMax()) {
            int aircount = map.get("aircount");
            aircount ++;
            map.put("aircount",aircount);
        }
        if (deviceData.getfPm() > judges.get(4).getWeixianMin()) {
            int pm25count = map.get("pm25count");
            pm25count ++;
            map.put("pm25count",pm25count);
        }
        if (deviceData.getfCarbonDioxide() > judges.get(5).getWeixianMin()) {
            int cotwocount = map.get("cotwocount");
            cotwocount ++ ;
            map.put("cotwocount",cotwocount);
        }
        if (deviceData.getfTvoc() > judges.get(6).getWeixianMin()) {
            int tvoccount = map.get("tvoccount");
            tvoccount ++;
            map.put("tvoccount",tvoccount);
        }
    }

    public static void experWarningCount(DeviceData deviceData, Map<String,Integer> map, List<JudgeValue> judges) {
        if (deviceData.getfTemperature() < judges.get(0).getWeixianMin() || deviceData.getfTemperature() > judges.get(0).getWeixianMax()) {
            int tempcount = map.get("tempcount");
            tempcount ++;
            map.put("tempcount",tempcount);
        }
        if (deviceData.getfHumidity() < judges.get(1).getWeixianMin() || deviceData.getfHumidity() > judges.get(1).getWeixianMax()) {
            int humcount = map.get("humcount");
            humcount ++;
            map.put("humcount",humcount);
        }
        if ((deviceData.getfPressure()) < judges.get(2).getWeixianMin()) {
            int presscount = map.get("presscount");
            presscount ++;
            map.put("presscount",presscount);
        }
        if (deviceData.getfExhaust() > judges.get(3).getWeixianMin() && deviceData.getfExhaust() < judges.get(3).getWeixianMax()) {
            int aircount = map.get("aircount");
            aircount ++;
            map.put("aircount",aircount);
        }
        if (deviceData.getfPm() > judges.get(4).getWeixianMin()) {
            int pm25count = map.get("pm25count");
            pm25count ++;
            map.put("pm25count",pm25count);
        }
        if (deviceData.getfCarbonDioxide() > judges.get(5).getWeixianMin()) {
            int cotwocount = map.get("cotwocount");
            cotwocount ++ ;
            map.put("cotwocount",cotwocount);
        }
        if (deviceData.getfTvoc() > judges.get(6).getWeixianMin()) {
            int tvoccount = map.get("tvoccount");
            tvoccount ++;
            map.put("tvoccount",tvoccount);
        }
    }

    public static void outdoorWarningCount(DeviceData deviceData, Map<String,Integer> map, List<JudgeValue> judges) {
        if (deviceData.getfTemperature() < judges.get(0).getWeixianMin() || deviceData.getfTemperature() > judges.get(0).getWeixianMax()) {
            int tempcount = map.get("tempcount");
            tempcount ++;
            map.put("tempcount",tempcount);
        }
        if (deviceData.getfHumidity() < judges.get(1).getWeixianMin() || deviceData.getfHumidity() > judges.get(1).getWeixianMax()) {
            int humcount = map.get("humcount");
            humcount ++;
            map.put("humcount",humcount);
        }
        if ((deviceData.getfPressure()) < judges.get(2).getWeixianMin() || (deviceData.getfPressure()) > judges.get(2).getWeixianMax()) {
            int presscount = map.get("presscount");
            presscount ++;
            map.put("presscount",presscount);
        }
        if (deviceData.getfExhaust() >=0 && deviceData.getfExhaust() < judges.get(3).getWeixianMin() || deviceData.getfExhaust() > judges.get(3).getWeixianMax()) {
            int aircount = map.get("aircount");
            aircount ++;
            map.put("aircount",aircount);
        }
        if (deviceData.getfPm() > judges.get(4).getWeixianMin()) {
            int pm25count = map.get("pm25count");
            pm25count ++;
            map.put("pm25count",pm25count);
        }
        if (deviceData.getfCarbonDioxide() > judges.get(5).getWeixianMin()) {
            int cotwocount = map.get("cotwocount");
            cotwocount ++ ;
            map.put("cotwocount",cotwocount);
        }
        if (deviceData.getfTvoc() > judges.get(6).getWeixianMin()) {
            int tvoccount = map.get("tvoccount");
            tvoccount ++;
            map.put("tvoccount",tvoccount);
        }
    }
}
